// pages/familydoctor/teams/team.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list: [{
        title: "重性精神初级包"
      },
      {
        title: "统一自定义初级包"
      },
      {
        title: "统一冠心病初级包"
      },
      {
        title: "统一严重精神障碍患者初级包"
      },
      {
        title: "统一残疾人初级包"
      },
      {
        title: "统一肺结核患者初级包"
      },
      {
        title: "统一计划生育特殊家庭初级包"
      },
      {
        title: "同意高血压初级包"
      },
      {
        title: "统一糖尿病初级包"
      },
    ],
    hospitalName: "桥东中心第一团队",
  },
  extract: function() {
    var hospitalName = this.data.hospitalName;
    var hospitalName = hospitalName.substr(0, 3) + '...';
    this.setData({
      hospitalName: hospitalName
    })
    console.log(this.data.hospitalName)
  },
  serverdetail: function(e) {
    var that = this
    var ff_id = e.currentTarget.dataset.ff_id
    var title = e.currentTarget.dataset.title
    wx.navigateTo({
      url: "/hyb_yl/doctor/pages/familydoctor/signing/signing?ff_id=" + ff_id + '&title=' + title,
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var bgc = wx.getStorageSync('color')
    var zid = options.zid
    if (options.ordernum) {
      var ordernum = options.ordernum
      //查询订单详情
      app.util.request({
        'url': 'entry/wxapp/docuser.jtdoc',
        data: {
          ordernum: ordernum
        },
        success(res) {
          console.log(res)
          that.setData({
            fuwbao: res.data
          })
        }
      })
    }

    wx.setNavigationBarColor({
      frontColor: "#ffffff",
      backgroundColor: bgc,
    })
    var that = this
    var t_id = options.t_id
    app.util.request({
      'url': 'entry/wxapp/Office.fwlist',
      data: {
        t_id: t_id
      },
      success(res) {
        console.log(res)
        var list = res.data
        that.setData({
          crowd: list,
        })
      }
    })
    var sid = options.sid
    var key = options.key
    var name = options.name
    var teamname = options.teamname
    that.setData({
      t_id: t_id,
      sid: sid,
      key: key,
      name: name,
      bgc: bgc,
      teamname: teamname,
      q_id: options.q_id,
      ordernum: options.ordernum,
      zid: zid
    })
    that.extract()
    wx.setNavigationBarTitle({
      title: '服务详情'
    })
    that.getTeamoffice()
    that.getMydangan()

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },
  getTeamoffice() {
    var that = this
    var t_id = that.data.t_id
    app.util.request({
      'url': 'entry/wxapp/Office.qianyue',
      data: {
        t_id: t_id
      },
      success(res) {
        console.log(res)
        that.setData({
          detail: res.data
        })
      }
    })
  },
  adduser(e) {
    var that = this
    wx.showModal({
      content: '只能选择您本人的健康档案',
      success: function(res) {
        if (res.confirm) {
          wx.navigateTo({
            url: '/hyb_yl/zhuanjiasubpages/pages/huanzhexinxi/huanzhexinxi',
          })
        }
      }

    })
  },
  //查询自己的健康档案
  getMydangan() {
    var that = this
    app.util.request({
      'url': 'entry/wxapp/user.ifself',
      'data': {
        openid: wx.getStorageSync('openid'),
      },
      success: function(res) {
        console.log(res)
        that.setData({
          names: res.data.names,
          j_id: res.data.j_id,
        })
      }
    })
  },
  pay() {
    var that = this
    var fw = that.data.fw

    app.util.request({
      'url': 'entry/wxapp/docuser.pay',
      header: {
        "Content-Type": "application/xml"
      },
      method: "GET",
      data: {
        openid: wx.getStorageSync('openid'),
        z_tw_money: fw.money
      },
      success: function(res) {
        console.log(res);
        wx.requestPayment({
          'timeStamp': res.data.timeStamp,
          'nonceStr': res.data.nonceStr, //字符串随机数
          'package': res.data.package,
          'signType': res.data.signType,
          'paySign': res.data.paySign,
          success: function(res) {
            console.log(res)
            //改变订单状态
            app.util.request({
              'url': 'entry/wxapp/docuser.updateorder',
              data: {
                q_id: that.data.q_id
              },
              success: function(res) {
                app.util.request({
                  'url': 'entry/wxapp/docuser.jtdoc',
                  data: {
                    q_id: that.data.q_id
                  },
                  success(res) {
                    console.log(res)
                    that.setData({
                      fw: res.data,
                      fuwbao: res.data.fuwbao,
                      q_id: that.data.q_id
                    })
                  }
                })
              }
            })
          }
        })
      }
    })
  },
  quxiao() {
    var that = this
    var q_id = that.data.q_id
    wx.showModal({
      content: '是否取消申请',
      success: function(res) {
        if (res.confirm) {
          app.util.request({
            'url': 'entry/wxapp/docuser.updatequxiao',
            data: {
              q_id: q_id
            },
            success: function(res) {
              console.log(res)
              wx.showToast({
                title: '取消成功',
                success: function(res) {
                  setTimeout(function() {
                    wx.navigateBack({
                      detail: 1
                    })
                  }, 1000)
                }
              })

            }
          })
        }
      }
    })
  },
  cxshenq() {
    //家庭医生
    //sid = 8 & key=zhuanjiatuandui & name=家庭医生
    var that = this
    var sid = that.data.sid
    var key = 'zhuanjiatuandui'
    var name = '家庭医生'
    wx.showModal({
      content: '是否重新申请',
      success: function(res) {
        if (res.confirm) {
          wx.redirectTo({
            url: '/hyb_yl/doctor/pages/familydoctor/mydoctor/mydoctor?key=' + key + '&name=' + name + '&sid=',
          })
        }
      }
    })
  }
})